/**   
 * @Title: NewLoadingCommunicater.java 
 * @Package com.esun.rabbit2.communicaters 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author: Billy Qigs@500wan.com   
 * @date: 2012-7-10 下午3:35:01  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Key;
import com.esun.model.LoadingInfo;
import com.esun.network.ServerCommunicater;
import com.esun.util.HashMapUtil;

/**
 * @ClassName: NewLoadingCommunicater
 * @Description: 新优化后的loading通信接口
 * @author: Billy Qigs@500wan.com
 * @date: 2012-7-10 下午3:35:01
 * 
 */
public class NewLoadingCommunicater extends ServerCommunicater {

	/**
	 * @Title: isCommunicatedSucceed
	 * @Description: loading界面获取数据通信接口
	 * @param: @param username 用户名
	 * @param: @param userpwd 用户密码
	 * @param: @param channel 渠道号
	 * @param: @param version 版本号
	 * @param: @param userimei push登陆用户名--唯一吗
	 * @param: @return 是否成功
	 * @param: @throws ClientProtocolException
	 * @param: @throws IOException
	 * @param: @throws ParserConfigurationException
	 * @param: @throws SAXException
	 */
	public boolean isCommunicatedSucceed(String username, String userpwd, String channel, String version, String userimei, String useragent, String IMEI) throws ClientProtocolException, IOException,
			ParserConfigurationException, SAXException {
		boolean isSucceed = false;

		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

		list.add(HashMapUtil.getMapItem(BussinessCode.PASER_MID, BussinessCode.MID_NEW_LOADING_COMMUNICATER));
		list.add(HashMapUtil.getMapItem(Key.KEY_USERNAME, username));
		list.add(HashMapUtil.getMapItem(Key.KEY_USERPASS, userpwd));
		list.add(HashMapUtil.getMapItem(Key.KEY_CHANNEL, channel));
		list.add(HashMapUtil.getMapItem(Key.KEY_VERSION, version));
		list.add(HashMapUtil.getMapItem(Key.KEY_USERIMEI, userimei));
		list.add(HashMapUtil.getMapItem(Key.KEY_USERAGENT, useragent));
		list.add(HashMapUtil.getMapItem(Key.KEY_MBIMEI, IMEI));

		super.getServerResponse(list, true);

		if (super.getState() == 100) {
			isSucceed = true;
		} else {
			isSucceed = false;
		}

		return isSucceed;
	}

	/**
	 * @Title: updateInfo
	 * @Description: 更新保存接口返回数据
	 * @return: void 返回类型
	 */
	public void updateInfo() {

		LoadingInfo info = LoadingInfo.getInstance();
		Hashtable<String, String> list = new Hashtable<String, String>();
		list = super.getResult();

		if (list != null) {
			info.setUsername(list.get(Key.KEY_USERNAME));
			info.setMoney(list.get(Key.KEY_MONEY));
			info.setFreezemoney(list.get(Key.KEY_FREEZEMONEY));
			info.setCk(list.get(Key.KEY_CK));
			info.setErrcount(list.get(Key.KEY_ERRCOUNT));
			info.setResultcode(list.get(Key.KEY_RESULTCODE));
			info.setIsmustupdate(list.get(Key.KEY_ISMUSTUPDATE));
			info.setIsupdate(list.get(Key.KEY_ISUPDATE));
			info.setUpdateurl(list.get(Key.KEY_UPDATEURL));
			info.setUpdatenotes(list.get(Key.KEY_UPDATENOTES));
			info.setIsstop(list.get(Key.KEY_ISSTOP));
			info.setStopnotes(list.get(Key.KEY_STOPNOTES));
			info.setLotid(list.get(Key.KEY_LOTID));
			info.setLatestVersionNum(list.get(Key.KEY_LATESTVERSION));
		}
	}

}
